package com.society.sgsc.dict.service.impl;


import com.baomidou.mybatisplus.annotation.Version;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.society.sgsc.dict.mapper.RoleMapper;
import com.society.sgsc.dict.service.RoleService;
import com.society.sgsc.entities.Role;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;


/**
 * 角色
 *      因为角色权限是由角色名称来进行分的，所以
 */
@Service
@Transactional
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {

    @Resource
    RoleMapper roleMapper;

    @Override
    public int saveRole(Role role) throws Exception {

        QueryWrapper<Role> wrapper = new QueryWrapper<>();
        wrapper.eq("role_name", role.getRoleName());
        Role role1 = roleMapper.selectOne(wrapper);
        if(null == role1) {
            return roleMapper.insert(role);
        }
        return 2002;
    }

}
